from django.db import models

# Create your models here.
#国家模型类
from ERP_system.utils.basemodels import BaseModel,BaseModel2


class Nation(models.Model):
    id=models.IntegerField(primary_key=True)
    n_name=models.CharField('国家名称',max_length=50)

    class Meta:
        db_table='nation'
        verbose_name='国家表'
        verbose_name_plural=verbose_name
        ordering=['id']

    def __str__(self):
        return self.n_name


#省份模型类
class Province(models.Model):
    id=models.IntegerField(primary_key=True)
    p_name=models.CharField('省份名称',max_length=50)
    nation=models.ForeignKey('Nation',related_name='province_list',on_delete=models.CASCADE)

    class Meta:
        db_table='province'
        verbose_name='省份表'
        verbose_name_plural=verbose_name
        ordering=['id']

    def __str__(self):
        return self.p_name

#城市模型类
class City(models.Model):
    id=models.IntegerField(primary_key=True)
    c_name=models.CharField('城市名称',max_length=50)
    province=models.ForeignKey('Province',related_name='city_list',on_delete=models.CASCADE)

    class Meta:
        db_table='city'
        verbose_name='城市表'
        verbose_name_plural=verbose_name
        ordering=['id']

    def __str__(self):
        return self.c_name

#供应商模型类
class SupplierModel(BaseModel2):
    name=models.CharField(max_length=100,verbose_name='供应商名字',unique=True)
    mobile=models.CharField('手机号码',max_length=11,null=True,blank=True)
    phone=models.CharField('联系电话',max_length=22,null=True,blank=True)
    contacts_name=models.CharField('联系人名',max_length=22,null=True,blank=True)
    email=models.CharField('电子邮箱',max_length=50,null=True,blank=True)
    ratepayer_number=models.CharField('纳税人识别号码',max_length=50,null=True,blank=True)
    bank=models.CharField('开户银行',max_length=50,null=True,blank=True)
    account_number=models.CharField('银行账号',max_length=50,null=True,blank=True)
    nation=models.CharField('国家',max_length=50)
    province=models.CharField('省份',max_length=50)
    city=models.CharField('城市',max_length=50)
    adress=models.CharField('详细地址',max_length=50)
    remark=models.CharField('备注',max_length=512,null=True,blank=True)
    init_pay=models.DecimalField('初期应付',max_digits=20,decimal_places=2,null=True,blank=True)
    current_pay=models.DecimalField('末期应付',max_digits=20,decimal_places=2,null=True,blank=True)
    order_number=models.IntegerField('排序号码',default=100)

    class Meta:
        db_table='t_supplier'
        verbose_name='供应商'
        verbose_name_plural=verbose_name
        ordering=['order_number','id']

    def __str__(self):
        return self.name


#客户模型类
class CustomerModel(BaseModel2):
    name=models.CharField(max_length=100,verbose_name='客户名字',unique=True)
    mobile=models.CharField('手机号码',max_length=11,null=True,blank=True)
    phone=models.CharField('联系电话',max_length=22,null=True,blank=True)
    contacts_name=models.CharField('联系人名',max_length=22,null=True,blank=True)
    email=models.CharField('电子邮箱',max_length=50,null=True,blank=True)
    ratepayer_number=models.CharField('纳税人识别号码',max_length=50,null=True,blank=True)
    bank=models.CharField('开户银行',max_length=50,null=True,blank=True)
    account_number=models.CharField('银行账号',max_length=50,null=True,blank=True)
    nation=models.CharField('国家',max_length=50)
    province=models.CharField('省份',max_length=50)
    city=models.CharField('城市',max_length=50)
    adress=models.CharField('详细地址',max_length=50)
    remark=models.CharField('备注',max_length=512,null=True,blank=True)
    init_receivable=models.DecimalField('初期应收',max_digits=20,decimal_places=2,null=True,blank=True)
    current_receivable=models.DecimalField('末期应收',max_digits=20,decimal_places=2,null=True,blank=True)
    order_number=models.IntegerField('排序号码',default=100)

    class Meta:
        db_table='t_customer'
        verbose_name='客户'
        verbose_name_plural=verbose_name
        ordering=['order_number','id']

    def __str__(self):
        return self.name


# 仓库模型类
class WarehouseModel(BaseModel2):
    name = models.CharField(max_length=100, verbose_name='仓库名称', unique=True)
    nation = models.CharField('国家', max_length=50,null=True,blank=True)
    province = models.CharField('省份', max_length=50,null=True,blank=True)
    city = models.CharField('城市', max_length=50,null=True,blank=True)
    adress = models.CharField('详细地址', max_length=50,null=True,blank=True)
    remark = models.CharField('备注', max_length=512, null=True, blank=True)
    warehouse_fee=models.DecimalField('仓库费用(元/天/KG)',max_digits=10,decimal_places=2)
    truckage=models.DecimalField('搬运费用',max_digits=10,decimal_places=2,blank=True)
    order_number = models.IntegerField('排序号码', default=100)
    is_default=models.BooleanField('是否是默认的仓库',default=False)
    #用户模型来自于sys_manager的app中
    leader_user=models.ForeignKey('sys_manager.UserModel',null=True,blank=True,on_delete=models.CASCADE)
    class Meta:
        db_table = 't_warehouse'
        verbose_name = '仓库'
        verbose_name_plural = verbose_name
        ordering = ['order_number', 'id']

    def __str__(self):
        return self.name

class AccountModel(BaseModel2):
    name = models.CharField(max_length=100, verbose_name='仓库名称', unique=True)
    number_code=models.CharField('编号',max_length=28,unique=True)
    remark = models.CharField('备注', max_length=512, null=True, blank=True)
    init_amount=models.DecimalField('初期金额',max_digits=10,decimal_places=2,blank=True,null=True)
    balance=models.DecimalField('余额',max_digits=10,decimal_places=2,blank=True,null=True)
    order_number = models.IntegerField('排序号码', default=100)
    is_default = models.BooleanField('是否是默认的仓库', default=False)

    class Meta:
        db_table = 't_account'
        verbose_name = '仓库结算'
        verbose_name_plural = verbose_name
        ordering = ['order_number', 'id']

    def __str__(self):
        return self.name


